package o;

import android.text.TextUtils;
import android.util.Pair;
import com.huawei.appgallery.agwebview.whitelist.WapDomainInfo;
import com.huawei.hms.framework.network.util.HttpUtils;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class bbd {
    private static final Map<String, b> ˊ = new HashMap();
    private static final byte[] ˎ = new byte[0];
    private static final Map<String, b> ˏ = new HashMap();
    private static List<WapDomainInfo> ॱ = new ArrayList();

    public enum b {
        ST,
        APP_DETAIL,
        INTERNAL,
        H5GAME,
        EXTRA,
        EXTRA_JS,
        EXPLOR,
        INSTALL
    }

    static {
        ˊ.put("ST", b.ST);
        ˊ.put("INTERNAL", b.INTERNAL);
        ˊ.put("APPDETAIL", b.APP_DETAIL);
        ˊ.put("H5", b.H5GAME);
        ˊ.put("EXTRA", b.EXTRA);
        ˊ.put("EXTRA_JS", b.EXTRA_JS);
        ˊ.put("EXPLOR", b.EXPLOR);
        ˊ.put("INSTALL", b.INSTALL);
        ˏ.put("INSTALL", b.INSTALL);
    }

    public static void ˋ(List<WapDomainInfo> list) {
        List arrayList = new ArrayList();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            WapDomainInfo wapDomainInfo = (WapDomainInfo) it.next();
            if (!(TextUtils.isEmpty(wapDomainInfo.ˊ()) || TextUtils.isEmpty(wapDomainInfo.ˏ()))) {
                if (!ˊ.containsKey(wapDomainInfo.ˏ())) {
                    if (Logger.ˎ()) {
                        azh.ˏ.ˋ("WebViewDispatcher", "saveWapDomainList remove:" + wapDomainInfo.ˏ());
                    }
                    it.remove();
                } else if (TextUtils.isEmpty(wapDomainInfo.ˊ())) {
                    azh.ˏ.ˊ("WebViewDispatcher", "saveWapDomainList, invalid wapDomainInfo, wapDomainInfo:" + wapDomainInfo.ˏ());
                } else {
                    WapDomainInfo wapDomainInfo2 = new WapDomainInfo();
                    wapDomainInfo2.ˏ(wapDomainInfo.ॱ());
                    wapDomainInfo2.ˎ(wapDomainInfo.ˏ());
                    wapDomainInfo2.ˊ(wapDomainInfo.ˊ());
                    arrayList.add(wapDomainInfo2);
                }
            }
        }
        if (arrayList.size() > 0) {
            long currentTimeMillis = System.currentTimeMillis();
            ˊ(arrayList);
            bbb.ˋ(list, currentTimeMillis);
        }
    }

    private static void ˊ(List<WapDomainInfo> list) {
        try {
            synchronized (ˎ) {
                Iterator it = list.iterator();
                while (it.hasNext()) {
                    WapDomainInfo wapDomainInfo = (WapDomainInfo) it.next();
                    if (!ˊ.containsKey(wapDomainInfo.ˏ())) {
                        if (Logger.ˎ()) {
                            azh.ˏ.ˏ("WebViewDispatcher", "updateDomainList remove:" + wapDomainInfo.ˏ());
                        }
                        it.remove();
                    }
                }
                ॱ.clear();
                ॱ.addAll(list);
                Collections.sort(ॱ);
            }
        } catch (Throwable e) {
            azh.ˏ.ˊ("WebViewDispatcher", "updateDomainList error", e);
        }
    }

    public static boolean ˏ(String str) {
        return ˊ(b.H5GAME, str);
    }

    public static boolean ˎ(String str) {
        return ˊ(b.APP_DETAIL, str);
    }

    public static boolean ˏ(String str, String str2) {
        Pattern compile = Pattern.compile("^(http://|https://)", 2);
        Matcher matcher = compile.matcher(str);
        Matcher matcher2 = compile.matcher(str2);
        boolean find = matcher.find();
        boolean find2 = matcher2.find();
        if (find && find2) {
            return str.startsWith(str2);
        }
        if (find) {
            return str.substring(matcher.end(), str.length()).startsWith(str2);
        }
        if (find2) {
            return str.startsWith(str2.substring(matcher2.end(), str2.length()));
        }
        return str.startsWith(str2);
    }

    private static Pair<String, List<String>> ˊ(b bVar) {
        if (!ॱ()) {
            return null;
        }
        List arrayList = new ArrayList();
        synchronized (ˎ) {
            String str = null;
            for (WapDomainInfo wapDomainInfo : ॱ) {
                if (!(wapDomainInfo == null || TextUtils.isEmpty(wapDomainInfo.ˊ()) || TextUtils.isEmpty(wapDomainInfo.ˏ()))) {
                    String str2;
                    String ˏ = wapDomainInfo.ˏ();
                    if (ˊ.get(ˏ) == bVar) {
                        arrayList.add(wapDomainInfo.ˊ());
                        str2 = ˏ;
                    } else {
                        str2 = str;
                    }
                    str = str2;
                }
            }
        }
        if (dof.ॱ(str) || arrayList.size() <= 0) {
            return null;
        }
        return new Pair(str, arrayList);
    }

    private static boolean ˊ(b bVar, String str) {
        if (bVar == null || dof.ॱ(str)) {
            return false;
        }
        Pair ˊ = ˊ(bVar);
        if (!(ˊ == null || ˊ.second == null || ((List) ˊ.second).size() <= 0)) {
            for (String ˊ2 : (List) ˊ.second) {
                if (ˊ((String) ˊ.first, ˊ2, str)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static azp ॱ(String str) {
        if (ˋ(str)) {
            if (!ॱ()) {
                return null;
            }
            synchronized (ˎ) {
                for (WapDomainInfo wapDomainInfo : ॱ) {
                    if (wapDomainInfo != null && !TextUtils.isEmpty(wapDomainInfo.ˊ()) && !TextUtils.isEmpty(wapDomainInfo.ˏ()) && !ˏ.containsKey(wapDomainInfo.ˏ()) && ˊ(wapDomainInfo.ˏ(), wapDomainInfo.ˊ(), str)) {
                        azp ᐝ = ᐝ(wapDomainInfo.ˏ());
                        return ᐝ;
                    }
                }
                return azp.NOINLIST;
            }
        } else if (ˏ(str)) {
            return azp.H5GAME;
        } else {
            return azp.EXPLOR;
        }
    }

    public static boolean ˊ(String str, String str2, String str3) {
        boolean z = false;
        if (!(dof.ˋ(str2) || str2.contains("*"))) {
            if (dof.ˋ(str3) || str3.contains("..\\") || str3.contains("../")) {
                azh.ˏ.ˏ("WebViewDispatcher", "illegal url");
            } else {
                if ("H5".equals(str)) {
                    if (!(str2.startsWith(HttpUtils.HTTP_PREFIX) || str2.startsWith("https://"))) {
                        str2 = "https://" + str2;
                    }
                } else if (!str2.startsWith("https://")) {
                    str2 = "https://" + str2;
                }
                try {
                    z = ˋ(str3, str2);
                } catch (Exception e) {
                    azh.ˏ.ˏ("WebViewDispatcher", "checkByURI  error");
                }
            }
        }
        return z;
    }

    private static boolean ˋ(String str, String str2) throws Exception {
        URI uri = new URI(str2);
        String host = uri.getHost();
        String path = uri.getPath();
        int port = uri.getPort();
        if (host == null || !host.contains(".")) {
            return false;
        }
        URI uri2 = new URI(str);
        String host2 = uri2.getHost();
        String path2 = uri2.getPath();
        int port2 = uri2.getPort();
        if (host2 == null || port != port2) {
            return false;
        }
        if ((host2.equals(host) || host2.endsWith("." + host)) && path != null && path2 != null && path2.startsWith(path)) {
            return true;
        }
        return false;
    }

    private static azp ᐝ(String str) {
        if (str.startsWith("EXPLOR")) {
            return azp.EXPLOR;
        }
        if (str.startsWith("EXTRA")) {
            return azp.EXTRA;
        }
        Object obj = -1;
        switch (str.hashCode()) {
            case 2285:
                if (str.equals("H5")) {
                    obj = null;
                    break;
                }
                break;
        }
        switch (obj) {
            case null:
                return azp.H5GAME;
            default:
                return azp.INTERNAL;
        }
    }

    public static boolean ˊ(String str) {
        return Pattern.compile("^(http://)", 2).matcher(str).find();
    }

    public static boolean ˋ(String str) {
        return Pattern.compile("^(https://)", 2).matcher(str).find();
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static boolean ॱ() {
        /*
        r0 = 1;
        r1 = ˎ;
        monitor-enter(r1);
        r2 = ॱ;	 Catch:{ all -> 0x001f }
        r2 = r2.size();	 Catch:{ all -> 0x001f }
        if (r2 <= 0) goto L_0x000e;
    L_0x000c:
        monitor-exit(r1);	 Catch:{ all -> 0x001f }
    L_0x000d:
        return r0;
    L_0x000e:
        monitor-exit(r1);	 Catch:{ all -> 0x001f }
        r1 = o.bbb.ˊ();
        if (r1 == 0) goto L_0x0022;
    L_0x0015:
        r2 = r1.size();
        if (r2 <= 0) goto L_0x0022;
    L_0x001b:
        ˊ(r1);
        goto L_0x000d;
    L_0x001f:
        r0 = move-exception;
        monitor-exit(r1);	 Catch:{ all -> 0x001f }
        throw r0;
    L_0x0022:
        r0 = o.azh.ˏ;
        r1 = "WebViewDispatcher";
        r2 = "no wap white list";
        r0.ˏ(r1, r2);
        r0 = 0;
        goto L_0x000d;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.bbd.ॱ():boolean");
    }

    public static List<WapDomainInfo> ˎ() {
        if (!ॱ()) {
            return null;
        }
        List arrayList;
        synchronized (ˎ) {
            arrayList = new ArrayList(ॱ);
        }
        return arrayList;
    }

    public static boolean ʼ(String str) {
        return "EXTRA".equals(str);
    }

    public static boolean ʻ(String str) {
        return ˊ(b.INSTALL, str);
    }
}
